/**
 * Classe responsável por exibir uma janela de dialogo com o usuario para a  escola da cor atual do jogo.
 * 
 * @author Claudio
 *
 */

@SuppressWarnings("serial")
public class EscolherCor extends javax.swing.JDialog {

		    private Cor corSelecionada;
		    
		    public EscolherCor(java.awt.Frame parent, boolean modal) {
		        super(parent, modal);
		        initComponents();
		        corSelecionada = null;
		    }

		    private void initComponents() {
		        buttonsPane = new javax.swing.JPanel();
		        redButton = new javax.swing.JButton();
		        greenButton = new javax.swing.JButton();
		        blueButton = new javax.swing.JButton();
		        yellowButton = new javax.swing.JButton();
		        labelPane = new javax.swing.JPanel();
		        jLabel1 = new javax.swing.JLabel();
		        
		        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
		        setName("colorChooser");
		        setModal(true);
		        setResizable(true);
		        
		        redButton.setForeground(java.awt.Color.white);
		        redButton.setText("Vermelho");
		        redButton.setBackground(new java.awt.Color(204, 0, 0));
		        redButton.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                redButtonActionPerformed(evt);
		            }
		        });
		        
		        buttonsPane.add(redButton);
		        
		        greenButton.setForeground(java.awt.Color.white);
		        greenButton.setText("Verde");
		        greenButton.setBackground(new java.awt.Color(0, 102, 0));
		        greenButton.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                greenButtonActionPerformed(evt);
		            }
		        });
		        
		        buttonsPane.add(greenButton);
		        
		        blueButton.setForeground(java.awt.Color.white);
		        blueButton.setText("Azul");
		        blueButton.setBackground(new java.awt.Color(0, 0, 204));
		        blueButton.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                blueButtonActionPerformed(evt);
		            }
		        });
		        
		        buttonsPane.add(blueButton);
		        
		        yellowButton.setForeground(java.awt.Color.white);
		        yellowButton.setText("Amarelo");
		        yellowButton.setBackground(new java.awt.Color(255, 204, 0));
		        yellowButton.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                yellowButtonActionPerformed(evt);
		            }
		        });
		        
		        buttonsPane.add(yellowButton);
		        
		        getContentPane().add(buttonsPane, java.awt.BorderLayout.CENTER);
		        
		        labelPane.setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
		        jLabel1.setText("Selecione a cor:");
		        labelPane.add(jLabel1);
		        
		        getContentPane().add(labelPane, java.awt.BorderLayout.NORTH);
		        
		        pack();
		        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		        setLocation((screenSize.width-getWidth())/2,(screenSize.height-getHeight())/2);
		    }
			
			public Cor getColor() {
				this.setVisible(true);;
				
				return corSelecionada;
			}
			
		    private void blueButtonActionPerformed(java.awt.event.ActionEvent evt) {
		        corSelecionada = Cor.AZUL;
		        closeDialog();
		    }

		    private void yellowButtonActionPerformed(java.awt.event.ActionEvent evt) {
		        corSelecionada = Cor.AMARELO;
		        closeDialog();
		    }

		    private void greenButtonActionPerformed(java.awt.event.ActionEvent evt) {
		        corSelecionada = Cor.VERDE;
		        closeDialog();
		    }

		    private void redButtonActionPerformed(java.awt.event.ActionEvent evt) {
		        corSelecionada = Cor.VERMELHO;
		        closeDialog();
		    }

		    private void closeDialog() {
		        setVisible(false);
		        dispose();
		    }

		    private javax.swing.JPanel buttonsPane;
		    private javax.swing.JButton redButton;
		    private javax.swing.JButton greenButton;
		    private javax.swing.JButton blueButton;
		    private javax.swing.JButton yellowButton;
		    private javax.swing.JPanel labelPane;
		    private javax.swing.JLabel jLabel1;

		}